#include "Camera.h"

Camera::Camera(void)
{
}

Camera::~Camera(void)
{
}

void Camera::init(ISceneManager *smgr,ISceneNode * node)
{
	//ESPECIFICA TIPO DE CAMERA
	tipoCamera = TERCEIRA;

	if(tipoCamera == GODVIEW){
		camera = smgr->addCameraSceneNode(node);
		camera->setPosition(core::vector3df(node->getPosition().X,node->getPosition().Y + 130, node->getPosition().Z - 100));
		camera->setTarget(node->getPosition());
	}else{
		// camera registry
		cameraOrbit = 90;
		cameraAngle = 45;
		cameraDistance =60;
		cameraOrbitOld = 0;
		cameraAngleOld = 0; 

		playerCompass = 30;
		playerTurnTo = 0;
		playerTurnSpeed = 1;
		playerMoveSpeed = 1.00; 

		// setup the camera
  		camera = smgr->addCameraSceneNode(node, sphericalXYZ(cameraOrbit,cameraAngle,cameraDistance),node->getPosition());


	}
}
//ATUALIZA A CAMERA
void Camera::atualizaCamera(ISceneNode * node)
{
	//VERIFICA TIPO DE CAMERA
	if (tipoCamera == GODVIEW){
		camera->setRotation(node->getRotation());
		camera->setTarget( node->getPosition() );
		camera->updateAbsolutePosition(); 
	}else{
		      // orient camera
      camera->setPosition(sphericalXYZ(cameraOrbit,cameraAngle,cameraDistance)); 
	}
}
ICameraSceneNode* Camera::getCamera()
{
	return camera;
}
TipoCamera Camera::getTipoCamera()
{
	return tipoCamera;
}

vector3df Camera::sphericalXYZ(f32 compassAngle, f32 elevationAngle, f32 radius){

   compassAngle = compassAngle * -1;
   elevationAngle = elevationAngle * -1;

   elevationAngle = elevationAngle + 90;

   f32 x = radius * cos(compassAngle * PI/180.0f ) * sin(elevationAngle * PI/180.0f );
   f32 z = radius * sin(compassAngle * PI/180.0f ) * sin(elevationAngle * PI/180.0f );
   f32 y = radius * cos(elevationAngle * PI/180.0f );

   vector3df result;
   result.X = x;
   result.Y = y;
   result.Z = z;
   return result;
} 

//GETS DA CAMERA
f32 Camera::getCameraOrbit()
{
	return cameraOrbit;
}
f32 Camera::getCameraAngle()
{
	return cameraAngle;
}
f32 Camera::getCameraDistance()
{
	return cameraDistance;
}
f32 Camera::getCameraOrbitOld()
{
	return cameraOrbitOld;
}
f32 Camera::getCameraAngleOld()
{
	return cameraAngleOld;
}

f32 Camera::getPlayerMoveSpeed()
{
	return playerMoveSpeed;
}
f32 Camera::getPlayerCompass()
{
	return playerCompass;
}
f32 Camera::getPlayerTurnTO()
{
	return playerTurnTo;
}
f32 Camera::getPlayerTurnSpeed()
{
	return playerTurnSpeed;
}
//SETS DA CAMERA
void Camera::setCameraOrbit(f32 var)
{
	cameraOrbit = var;
}

void Camera::setCameraOrbitOld(f32 var)
{
	cameraOrbitOld = var;
}

void Camera::setCameraAngle(f32 var)
{
	cameraAngle = var;
}

void Camera::setCameraAngleOld(f32 var)
{
	cameraAngleOld = var;
}
void Camera::setCameraDistance(f32 var)
{
	cameraDistance = var;
}

void Camera::setPlayerMoveSpeed(f32 var)
{
	playerMoveSpeed = var;
}
void Camera::setPlayerCompass(f32 var)
{
	playerCompass = var;
}
void Camera::setPlayerTurnTO(f32 var)
{
	playerTurnTo = var;
}
void Camera::setPlayerTurnSpeed(f32 var)
{
	playerTurnSpeed = var;
}





